package com.zr.sms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.zr.sms.model.Employee;
import com.zr.sms.service.SelectService;
import com.zr.sms.serviceimpl.SelectServiceImpl;
/**
 * 展现功能树功能业务层
 * @author wangbs
 *
 */
public class ShowfuncsServlet extends HttpServlet{
	   SelectService ss=new SelectServiceImpl();
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        		throws ServletException, IOException {
        	 doPost(req, resp);
        }
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        	throws ServletException, IOException {
        	resp.setCharacterEncoding("utf-8");
        	Employee emp=(Employee) req.getSession().getAttribute("currentemp");
        	int eid=emp.getEid();
        	int rid=ss.selectRidByEid(eid);//通过eid得到rid
        	
        	String rfuncs=ss.selectRfuncsByRid(rid);//通过角色id查询功能的字符串
        	int parentId=-1;
        	JSONArray funcs=ss.getFuncs(parentId, rfuncs);//返回对应的功能数组的json数组对象。写回jsp页面
             PrintWriter out=resp.getWriter();
      	     out.write(funcs.toString());
        	
                     
        }
}
